# -*- coding: cp1254 -*-
from PyQt4 import QtCore, QtGui, uic
from Crypto.Cipher import *
import kripto
import mail
import fileops
import os
import sys


class DemoImpl(QtGui.QMainWindow):
    def __init__(self, *args):
        QtGui.QWidget.__init__(self, *args)
        uic.loadUi("send.ui", self)
        self.statusBar().showMessage("Standby")
        
    @QtCore.pyqtSignature("") 
    def on_sendbtn_clicked(self):
        try:
            username=str(self.usernamelineEdit.text())
            password=str(self.passwordlineEdit.text())
            to=str(self.tolineEdit.text())
            subject=str(self.subjectlineEdit.text())
            smtp=str(self.smtplineEdit.text())
            message=str(self.messagetextEdit.toPlainText())
            key=str(self.keylineEdit.text())
        except:
            self.statusBar().showMessage("Please use only letter of the english alphabet")
            
        if len(username)>0 and len(password)>0 and len(to)>0 and len(subject)>0 and len(smtp)>0 and len(key)>0:
            self.statusBar().showMessage("Sending")
            if len(message)<120:
                test = kripto.gizlilik(key,"~",Blowfish,Blowfish.MODE_ECB)
                gizlenmis_metin = test.gizle(message)

                fileops.saveOutputFile(gizlenmis_metin)
                
                result=mail.mail(smtp,#Smtp server
                     username,#gmail account
                     password,#gmail account pass
                     to,#to
                     subject,#subject
                     "Python_Secured_E-Mail",#content
                     "pysecuredmailfile")#attachment

                self.statusBar().showMessage(result)

                os.remove('pysecuredmailfile')
            else:
                self.statusBar().showMessage("Message lenght can't be bigger than 120")
                    
        else:
            self.statusBar().showMessage("Fill All Fields")


app = QtGui.QApplication(sys.argv)
widget = DemoImpl()
widget.show()
app.exec_()

